package xyz.zyl2020.java8.datetime;

import java.time.Duration;

/**
 * @author ZhuYinglong
 * @date 2020/11/6 0006
 */
public class DurationDemo {

    public static void main(String[] args) {

        // 根据天获取实例
        Duration duration1 = Duration.ofDays(1);
        System.out.println("01: " + duration1);
        // 根据小时获取实例
        Duration duration2 = Duration.ofHours(10);
        System.out.println("02: " + duration2);
        // 根据分钟获取实例
        Duration duration3 = Duration.ofMinutes(20);
        System.out.println("03: " + duration3);
        // 根据秒获取实例
        Duration duration4 = Duration.ofSeconds(30);
        System.out.println("04: " + duration4);
        // 根据毫秒获取实例
        Duration duration5 = Duration.ofMillis(4000);
        System.out.println("05: " + duration5);

        // 从一个字符串中获取一个实例，如：PnDTnHnMn.nS，其中一天被认为是24小时
        Duration duration6 = Duration.parse("P2D");
        System.out.println("06: " + duration6);

    }
}
